package com.baoyouqun.controller.weixin;

import cn.dev33.satoken.stp.StpUtil;
import com.alibaba.cola.dto.SingleResponse;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baoyouqun.base.PageResponse;
import com.baoyouqun.domain.CreateCmd.UserSearchRecordCreateCmd;
import com.baoyouqun.domain.Query.UserSearchRecordQuery;
import com.baoyouqun.domain.VO.UserSearchRecordVO;
import com.baoyouqun.service.UserSearchRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("wx/userSearchRecord")
@Api(tags = "用户搜索记录表管理接口")
public class WxUserSearchRecordController {

    @Resource
    private UserSearchRecordService userSearchRecordService;

    @PostMapping("create")
    @ApiOperation("新增用户搜索记录表")
    public SingleResponse<UserSearchRecordVO> create(@RequestBody UserSearchRecordCreateCmd cmd) {
        return userSearchRecordService.create(cmd);
    }

    @GetMapping("page")
    @ApiOperation("分页查询用户搜索记录表")
    public PageResponse<UserSearchRecordVO> page(UserSearchRecordQuery query) {
        String userId = StpUtil.getLoginIdAsString();
        query.setUserId(userId);
        IPage<UserSearchRecordVO> page = userSearchRecordService.pageVo(query);
        return PageResponse.of(page.getRecords(), page.getTotal(), page.getCurrent(), page.getSize());
    }
}